/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.business.repository;

import me.zhengjie.business.domain.KB04;
import me.zhengjie.business.domain.KB04NEW;
import me.zhengjie.business.domain.vo.Kb04Vo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 照护年预留拨付表
* @author xiahongbo
* @date 2023-04-24
**/
public interface Kb04Repository extends JpaRepository<KB04, String>, JpaSpecificationExecutor<KB04> {


    /**
     * 查询照护年预留拨付表
     * @param akb020
     * @param aae001
     * @param aae140
     * @param cjt100
     * @param insuNo
     * @param pageable
     * @return
     */
    @Query(value = "select new me.zhengjie.business.domain.vo.Kb04Vo( " +
            "r1.aab034, " +
            "r1.akb020, " +
            "r1.akb021, " +
            "r1.aae001, " +
            "r1.aae140, " +
            "r1.cjt100, " +
            "r1.akb065, " +
            "r1.akb066, " +
            "r1.akb067, " +
            "r1.akb068, " +
            "r1.akb090, " +
            "r1.akb071, " +
            "r1.akb094, " +
            "r1.akb083, " +
            "r1.aae015, " +
            "r1.aae002Ks, " +
            "r1.aae002Zz, " +
            "r1.insuNo, " +
            "r1.inusName, " +
            "r1.id" +
            ") " +
            "from KB04 r1 " +
            " where  1=1 " +
            "   and (?1 IS NULL OR ?1 = '' OR r1.akb020 = ?1 ) "+
            "   and (?2 IS NULL OR ?2 = '' OR r1.aae140 = ?2 ) " +
            "   and (?3 IS NULL OR ?3 = '' OR r1.cjt100 = ?3 ) " +
            "   and (?4 IS NULL OR ?4 = '' OR r1.insuNo = ?4 ) " +
            "   and (r1.aae001 = ?5 ) "
            ,
            countQuery = "select count(*) from KB04 r1 " +
                " where 1=1 " +
                "   and (?1 IS NULL OR ?1 = '' OR r1.akb020 = ?1 ) " +
                "   and (?2 IS NULL OR ?2 = '' OR r1.aae140 = ?2 ) " +
                "   and (?3 IS NULL OR ?3 = '' OR r1.cjt100 = ?3 ) " +
                "   and (?4 IS NULL OR ?4 = '' OR r1.insuNo = ?4 ) " +
                "   and (r1.aae001 = ?5 ) " )
    Page<Kb04Vo> queryKB04PageList(String akb020, String aae140, String cjt100, String insuNo, Long aae001, Pageable pageable);


    @Query(value = "select new me.zhengjie.business.domain.vo.Kb04Vo( " +
            "r1.aab034, " +
            "r1.akb020, " +
            "r1.akb021, " +
            "r1.aae001, " +
            "r1.aae140, " +
            "r1.cjt100, " +
            "r1.akb065, " +
            "r1.akb066, " +
            "r1.akb067, " +
            "r1.akb068, " +
            "r1.akb090, " +
            "r1.akb071, " +
            "r1.akb094, " +
            "r1.akb083, " +
            "r1.aae015, " +
            "r1.aab034Name, " +
            "r1.aab034, " +
            "r1.insuNo, " +
            "r1.inusName, " +
            "r1.totle" +
            ") " +
            "from KB04NEW r1 " +
            " where  1=1 " +
            "   and (?1 IS NULL OR ?1 = '' OR r1.akb020 = ?1 ) "+
            "   and (?2 IS NULL OR ?2 = '' OR r1.aae140 = ?2 ) " +
            "   and (?3 IS NULL OR ?3 = '' OR r1.cjt100 = ?3 ) " +
            "   and (?4 IS NULL OR ?4 = '' OR r1.insuNo = ?4 ) " +
            "   and (r1.aae001 = ?5 ) "
            ,
            countQuery = "select count(*) from KB04NEW r1 " +
                    " where 1=1 " +
                    "   and (?1 IS NULL OR ?1 = '' OR r1.akb020 = ?1 ) " +
                    "   and (?2 IS NULL OR ?2 = '' OR r1.aae140 = ?2 ) " +
                    "   and (?3 IS NULL OR ?3 = '' OR r1.cjt100 = ?3 ) " +
                    "   and (?4 IS NULL OR ?4 = '' OR r1.insuNo = ?4 ) " +
                    "   and (r1.aae001 = ?5 ) " )
    Page<Kb04Vo> queryKB04NewPageList(String akb020, String aae140, String cjt100, String insuNo, Long aae001, Pageable pageable);


    @Query(value = "select new me.zhengjie.business.domain.vo.Kb04Vo( " +
            "r1.aab034, " +
            "r1.akb020, " +
            "r1.akb021, " +
            "r1.aae001, " +
            "r1.aae140, " +
            "r1.cjt100, " +
            "r1.akb065, " +
            "r1.akb066, " +
            "r1.akb067, " +
            "r1.akb068, " +
            "r1.akb090, " +
            "r1.akb071, " +
            "r1.akb094, " +
            "r1.akb083, " +
            "r1.aae015, " +
            "r1.aab034Name, " +
            "r1.aab034, " +
            "r1.insuNo, " +
            "r1.inusName, " +
            "r1.totle" +
            ") " +
            "from KB04NEW r1 " +
            " where  1=1 " +
            "   and (?1 IS NULL OR ?1 = '' OR r1.akb020 = ?1 ) "+
            "   and (?2 IS NULL OR ?2 = '' OR r1.aae140 = ?2 ) " +
            "   and (?3 IS NULL OR ?3 = '' OR r1.cjt100 = ?3 ) " +
            "   and (?4 IS NULL OR ?4 = '' OR r1.insuNo = ?4 ) " +
            "   and (r1.aae001 = ?5 ) " )
    List<Kb04Vo> queryKB04NewPageList(String akb020, String aae140, String cjt100, String insuNo, Long aae001);
}